package com.ruoyi.wxmp.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wxmp.entity.WxConfig;
import com.ruoyi.wxmp.service.IWxConfigService;
import com.ruoyi.wxmp.service.impl.WxConfigServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 微信公众号appid等配置信息 前端控制器
 * </p>
 *
 * @author yangxy
 * @since 2021-05-28
 */
@Api("微信配置信息管理")
@RestController
@RequestMapping("/wx-config")
public class WxConfigController extends BaseController {

    private IWxConfigService wxConfigService;

    /**
     * 分页查询
     * @param page
     * @param wxConfig
     * @return
     */
    @ApiOperation("获取列表")
    @GetMapping("/page")
    public AjaxResult getWxConfig(Page page, WxConfig wxConfig){
        return AjaxResult.success(wxConfigService.page(page, Wrappers.query(wxConfig)));
    }

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getWxConfigById(@PathVariable("id") String id){
        return AjaxResult.success(wxConfigService.getById(id));
    }

    /**
     * 新增
     * @param wxConfig
     * @return
     */
    @PutMapping
    public AjaxResult save(@RequestBody WxConfig wxConfig){


        return AjaxResult.success(wxConfigService.save(wxConfig));
    }

    /**
     * 删除，根据id
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable("id") String id){

        return AjaxResult.success(wxConfigService.removeById(id));
    }

    /**
     * 修改
     * @param wxConfig
     * @return
     */
    @PostMapping
    public AjaxResult updateById(@RequestBody WxConfig wxConfig){


        return AjaxResult.success(wxConfigService.updateById(wxConfig));
    }


}
